/*
 * @Author: Bing
 * @Date: 2024-02-01 18:11:16
 * @LastEditors: Bing
 * @LastEditTime: 2024-02-07 21:19:28
 * @Description: file content
 * @FilePath: \mi365plus\vite.config.ts
 */
import { defineConfig } from 'vite';
import uni from '@dcloudio/vite-plugin-uni';
import { UnifiedViteWeappTailwindcssPlugin as uvwt } from 'weapp-tailwindcss/vite';
import path from 'path';

const resolve = (p) => {
  return path.resolve(__dirname, p);
};

// https://vitejs.dev/config/
export default defineConfig({
  build: {
    // 开发阶段启用源码映射：https://uniapp.dcloud.net.cn/tutorial/migration-to-vue3.html#需主动开启-sourcemap
    sourcemap: process.env.NODE_ENV === 'development',
  },
  plugins: [
    uni(),
    uvwt({
      'rem2rpx': true,
    }),
  ],
  css: {
    postcss: {
      plugins: [
        require('tailwindcss')({
          // 注意此处，手动传入你 `tailwind.config.js` 的绝对路径
          config: resolve('./tailwind.config.js'),
        }),
        require('autoprefixer'),
      ],
    },
  },
  // #ifdef H5
  server: {
    proxy: {
      '^/api': {
        target: 'https://cf.emucoo.net/V1.1/api',
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/api/, ''),
      },
    },
  },
  // #endif
});
